//
//  SAFeedBackConsoultDetaileController.m
//  SunOn
//
//  Created by mc on 2017/5/4.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//  咨询详情界面

#import "SAFeedBackConsoultDetaileController.h"
#import "SAFeedBackConsoultDetaileFirstCell.h"
#import "SADepartmentCollectionTableViewCell.h"

@interface SAFeedBackConsoultDetaileController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tabview;

@property (weak, nonatomic) IBOutlet UIView *allview;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *allviewBottomLayout;
@property (weak, nonatomic) IBOutlet UITextField *commentTextfiled;
@property (weak, nonatomic) IBOutlet UIButton *sendbutton;

@end

@implementation SAFeedBackConsoultDetaileController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view insertSubview:self.tabview belowSubview:self.allview];
    SAViewRadius(self.sendbutton, 5);
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillshow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHid:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - view cycle
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIButton *back = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [back setBackgroundImage:SAImageNamed(@"ljiantou") forState:(UIControlStateNormal)];
    back.frame = CGRectMake(0, 0, 10, 19);
    [back addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *leftitem = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = leftitem;
    
    UIButton *collection = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [collection setBackgroundImage:SAImageNamed(@"shoucang2") forState:(UIControlStateNormal)];
    collection.frame = CGRectMake(0, 0, 18, 16);
    [collection addTarget:self action:@selector(collectionAction:) forControlEvents:(UIControlEventTouchUpInside)];
    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:collection];
    self.navigationItem.rightBarButtonItem = rightitem;
}
#pragma mark - custome method
- (void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}
//发送
- (IBAction)sendAction:(UIButton *)sender {
    
}

//收藏
- (void)collectionAction:(UIButton *)sender {
    NSData *data = UIImagePNGRepresentation(SAImageNamed(@"shoucang2"));
    NSData *data1 = UIImagePNGRepresentation(sender.currentBackgroundImage);
    if ([data isEqualToData:data1]) {
        [sender setBackgroundImage:SAImageNamed(@"shoucang") forState:(UIControlStateNormal)];
    }else {
        [sender setBackgroundImage:SAImageNamed(@"shoucang2") forState:(UIControlStateNormal)];
    }
}

#pragma mark - NSNotificationCenter

- (void)keyboardWillshow:(NSNotification *)notification {
    if ([self.commentTextfiled isFirstResponder]) {
        //获取键盘弹起时间
        double duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
        //获取键盘上端Y坐标
        CGFloat keyboardy = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
        [UIView animateWithDuration:duration animations:^{
            self.allviewBottomLayout.constant = keyboardy;
        }];
    }
}

- (void)keyboardWillHid:(NSNotification *)notification {
    //获取键盘弹起时间
    double duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    [UIView animateWithDuration:duration animations:^{
        self.allviewBottomLayout.constant = 0;
    }];
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        SAFeedBackConsoultDetaileFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAFeedBackConsoultDetaileFirstCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else {
        SADepartmentCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SADepartmentCollectionTableViewCell" forIndexPath:indexPath];
        [cell configureCellsImageHeight:0 CommentHeight:38];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 130;
    }
    return 111 + 44 + 11;
}
#pragma mark - setter&getter
- (UITableView *)tabview {
    if (!_tabview) {
        self.tabview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SASCREEN_WIDTH, SASCREEN_HEIGHT - 50) style:(UITableViewStylePlain)];
        self.tabview.delegate = self;
        self.tabview.dataSource = self;
        [self.tabview registerNib:[UINib nibWithNibName:@"SAFeedBackConsoultDetaileFirstCell" bundle:nil] forCellReuseIdentifier:@"SAFeedBackConsoultDetaileFirstCell"];
        [self.tabview registerNib:[UINib nibWithNibName:@"SADepartmentCollectionTableViewCell" bundle:nil] forCellReuseIdentifier:@"SADepartmentCollectionTableViewCell"];
        self.tabview.showsVerticalScrollIndicator = NO;
        self.tabview.showsHorizontalScrollIndicator = NO;
        self.tabview.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tabview;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
